package com.hh.flex.keygen;

import cn.hutool.core.util.ObjectUtil;
import com.hh.common.core.domain.BaseEntity;
import com.hh.common.utils.uuid.IdUtils;
import com.mybatisflex.core.keygen.IKeyGenerator;

/**
 * @description:  雪花算法
 * @author minliuhua
 * @date: 2023/5/1 16:32
 */
public class SnowFlakeKeyGenerator implements IKeyGenerator {

    @Override
    public Long generate(Object object, String keyColumn) {
        BaseEntity entity = (BaseEntity) object;
        if (ObjectUtil.isNotNull(entity.getId()))
        {
            return entity.getId();
        }
        return IdUtils.snowflakeId();
    }
}
